import 'package:flutter/material.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';

import '../../../resource/language/generated/l10n.dart';

CustomHeader get buildCustomHeader {
  return CustomHeader(
    headerBuilder: (BuildContext context,
        RefreshMode refreshState,
        double pulledExtent,
        double refreshTriggerPullDistance,
        double refreshIndicatorExtent,
        AxisDirection axisDirection,
        bool float,
        Duration? completeDuration,
        bool enableInfiniteRefresh,
        bool success,
        bool noMore) {
      Widget body;
      final title = refreshState.toString();
      if (title == 'RefreshMode.drag') {
        double turns = 0.0;
        print(pulledExtent);
        if(pulledExtent < 45){
          turns = 0.0;
        }
        if(pulledExtent > 45 && pulledExtent < 55){
          turns = -0.25;
        }
        if(pulledExtent > 55 ){
          turns = -0.5;
        }
        body = body = AnimatedRotation(
          duration: const Duration(milliseconds: 600),
          turns: turns,
          child: Icon(Icons.arrow_downward,color: Color(0xffc1c1c1c1),)
        );
      } else if (title == 'RefreshMode.armed') {
        body = Center(
          child: Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Container(
                width: 16,
                height: 16,
                margin: const EdgeInsets.only(left: 10),
                child: const CircularProgressIndicator(
                  strokeWidth: 1,
                ),
              ),
            ],
          ),
        );
      } else if (title == 'RefreshMode.refreshed') {
        body = Text(T.current.h1_success);
      } else if (title == 'RefreshMode.fail') {
        body = Text(T.current.h1_fail);
      } else {
        body = Text(T.current.h1_success);
      }
      return Container(
        height: 55.0,
        child: Center(child: body),
      );
    },
  );
}

CustomFooter get buildCustomFooter{
  return CustomFooter(
    footerBuilder: (BuildContext context,
        LoadMode loadState,
        double pulledExtent,
        double loadTriggerPullDistance,
        double loadIndicatorExtent,
        AxisDirection axisDirection,
        bool float,
        Duration? completeDuration,
        bool enableInfiniteLoad,
        bool success,
        bool noMore) {
      // 自定义Widget构建
      Widget body;
      final title = loadState.toString();
      if(title == 'LoadMode.load'){
        body = Center(
          child: Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Container(
                width: 16,
                height: 16,
                margin: const EdgeInsets.only(left: 10),
                child: const CircularProgressIndicator(
                  strokeWidth: 1,
                ),
              ),
            ],
          ),
        );
      } else if(title == 'LoadMode.drag'){
        body = Text('Load More');
      }else if(title == 'LoadMode.armed'){
        if(noMore){
          body = Text(T.current.h1_no_more);
        } else {
          body = Text(T.current.h1_load_more);
        }
      }  else if(title == 'LoadMode.done'){
        body = Container();
      } else if(title == 'LoadMode.fail'){
        body = Text(T.current.h1_fail);
      } else {
        body = Text(T.current.h1_no_more);
      }
      return Container(
        height: 55.0,
        child: Center(child: body),
      );
    },
  );
}